package com.traceability.trace.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.traceability.common.annotation.Log;
import com.traceability.common.core.controller.BaseController;
import com.traceability.common.core.domain.AjaxResult;
import com.traceability.common.enums.BusinessType;
import com.traceability.trace.domain.Agriculturalproducthash;
import com.traceability.trace.service.IAgriculturalproducthashService;
import com.traceability.common.utils.poi.ExcelUtil;
import com.traceability.common.core.page.TableDataInfo;

/**
 * hashController
 * 
 * @author xulin
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/traceability-trace/agriculturalproducthash")
public class AgriculturalproducthashController extends BaseController
{
    @Autowired
    private IAgriculturalproducthashService agriculturalproducthashService;

    /**
     * 查询hash列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:agriculturalproducthash:list')")
    @GetMapping("/list")
    public TableDataInfo list(Agriculturalproducthash agriculturalproducthash)
    {
        startPage();
        List<Agriculturalproducthash> list = agriculturalproducthashService.selectAgriculturalproducthashList(agriculturalproducthash);
        return getDataTable(list);
    }

    /**
     * 导出hash列表
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:agriculturalproducthash:export')")
    @Log(title = "hash", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Agriculturalproducthash agriculturalproducthash)
    {
        List<Agriculturalproducthash> list = agriculturalproducthashService.selectAgriculturalproducthashList(agriculturalproducthash);
        ExcelUtil<Agriculturalproducthash> util = new ExcelUtil<Agriculturalproducthash>(Agriculturalproducthash.class);
        util.exportExcel(response, list, "hash数据");
    }

    /**
     * 获取hash详细信息
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:agriculturalproducthash:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(agriculturalproducthashService.selectAgriculturalproducthashById(id));
    }

    /**
     * 新增hash
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:agriculturalproducthash:add')")
    @Log(title = "hash", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agriculturalproducthash agriculturalproducthash)
    {
        return toAjax(agriculturalproducthashService.insertAgriculturalproducthash(agriculturalproducthash));
    }

    /**
     * 修改hash
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:agriculturalproducthash:edit')")
    @Log(title = "hash", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agriculturalproducthash agriculturalproducthash)
    {
        return toAjax(agriculturalproducthashService.updateAgriculturalproducthash(agriculturalproducthash));
    }

    /**
     * 删除hash
     */
    @PreAuthorize("@ss.hasPermi('traceability-trace:agriculturalproducthash:remove')")
    @Log(title = "hash", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(agriculturalproducthashService.deleteAgriculturalproducthashByIds(ids));
    }

}
